package com.beem.project.beem.providers;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

public class DbManager {
	
	ContentResolver cr;
	
	public DbManager(ContentResolver cr) {
		super();
		this.cr = cr;
	}
	
	public Accounts lastAccounts(){
		Accounts account = null;
		String sortOrder = "_id DESC";
		Uri uri = Accounts.CONTENT_URI.buildUpon().appendQueryParameter("limit", "limit 1").build();
		Cursor c = cr.query(uri, null, null, null, sortOrder);
		if(c.moveToFirst()){
			account = getAccountsToCursor(c);
			c.close();
		}
		return account;
		
	}
	private Accounts getAccountsToCursor(Cursor c){
		Accounts account = new Accounts();
		account.setId(c.getInt(c.getColumnIndexOrThrow(Accounts._ID)));
		account.setAccountSharedPrefs(c.getString(c.getColumnIndexOrThrow(Accounts.ACCOUNT_SHARED_PREFS)));
		account.setAccountOrderby(c.getInt(c.getColumnIndexOrThrow(Accounts.ACCOUNT_ORDERBY)));
		return account;
	}
}
